package com.htsk.city.services.wechat.controller;


import com.htsk.city.services.core.domain.*;
import com.htsk.city.services.core.entity.PageInfo;
import com.htsk.city.services.core.entity.R;
import com.htsk.city.services.wechat.annotation.GetUserInfo;
import com.htsk.city.services.wechat.params.CommentQueryParam;
import com.htsk.city.services.wechat.params.PostQueryParam;
import com.htsk.city.services.wechat.params.PublishCommmentParam;
import com.htsk.city.services.wechat.params.PublishPostsParam;
import com.htsk.city.services.wechat.service.PostService;
import com.htsk.city.services.wechat.vo.CommentVO;
import com.htsk.city.services.wechat.vo.PostVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("posts")
public class PostController {

    @Resource
    private PostService postService;


    @GetMapping("listTopic")
    public R<List<Topic>> list(){
        return postService.listTopic();
    }


    @PostMapping("publish")
    public R<Long> publish(@GetUserInfo WxUser wxUser, @RequestBody PublishPostsParam publishPostsParam){
        return postService.publishPost(wxUser,publishPostsParam);
    }

    @PostMapping("query")
    public R<PageInfo<PostVO, Post>> query( @RequestBody PostQueryParam postQueryParam){
        return postService.pagePost(postQueryParam);
    }

    @PostMapping("queryMy")
    public R<PageInfo<PostVO, Post>> queryMy( @GetUserInfo WxUser wxUser,@RequestBody PostQueryParam postQueryParam){
        return postService.pageMyPost(wxUser,postQueryParam);
    }

    @GetMapping("likePost")
    public  R<PostVO> likePost(@GetUserInfo WxUser wxUser,@RequestParam("postId") Long postId){
        return postService.likePost(wxUser,postId);
    }
    @GetMapping("delPost")
    public  R<Long> delPost(@GetUserInfo WxUser wxUser,@RequestParam("postId") Long postId){
        return postService.delPost(wxUser,postId);
    }


    @PostMapping("publishCommment")
    public R<Long> publishCommment(@GetUserInfo WxUser wxUser, @RequestBody PublishCommmentParam publishCommmentParam){
        return postService.publishCommment(wxUser,publishCommmentParam);
    }

    @PostMapping("queryComment")
    public R<PageInfo<CommentVO, Comment>> queryComment(@RequestBody  CommentQueryParam commentQueryParam){
        return postService.queryComment(commentQueryParam);
    }

    @GetMapping("likeComment")
    public R<CommentVO> likeComment(@GetUserInfo WxUser wxUser,@RequestParam("commentId")Long commentId){
        return postService.likeComment(wxUser,commentId);
    }

    @PostMapping("readPost")
    public R<Boolean> readPost(@RequestBody  List<Long> postIds){
        return postService.readPost(postIds);
    }

    @GetMapping("delComment")
    public R<Long> delComment(@GetUserInfo WxUser wxUser,@RequestParam("commentId")Long commentId){
        return postService.delComment(wxUser,commentId);
    }
}
